﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.WebPartPages;
using System.Web.UI;
using Microsoft.SharePoint;
using RENIT.DragNDropUpload.Extensibility;

namespace RENIT.DragNDropUpload.Utils
{
    public static class WebPartsAnalizer
    {
        public static List<UploadTargetData> GetUploadTargets(Page page)
        {
            var contextUser = SPContext.Current.Web.CurrentUser;
            var manager = SPWebPartManager.GetCurrentWebPartManager(page);
            if (manager == null)
            {
                return new List<UploadTargetData>();
            }
            var result = new List<UploadTargetData>();
            foreach (System.Web.UI.WebControls.WebParts.WebPart part in manager.WebParts)
            {
                var data = WebPartsAdaptersManager.GetTargetData(part);
                if (data != null)
                {
                    result.Add(data);
                }
            }
            return result;
        }


        static WebPartsAnalizer()
        {
            WebPartsAdaptersManager.InitAdapters(new ListViewWebPartsAdapter());

        }

    }
}
